package test.my.com.myapplicationtest.recycleview_expand;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import test.my.com.myapplicationtest.R;

/**
 * Author : Cooper
 * Time : 2017/6/20  16:18
 * Description : ExpandRecycleView 上来加载view
 */

public class LoadingFooterView extends RelativeLayout{

    public static final int STATUS_LOADING = 0x003; // 正在加载
    public static final int STATUS_LOAD_COMPLETEED = 0x004; // 加载完毕
    public static final int STATUS_LOAD_OVER = 0x005; // 已经到底了
    public static final int STATUS_NORMAL = 0x006; // 正常状态

    private Context mContext;
    private TextView tvLoadContet;
    public int mStatus;

    public LoadingFooterView(Context context) {
        super(context);
        init(context);
    }

    public LoadingFooterView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public LoadingFooterView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        this.mContext = context;
        tvLoadContet = new TextView(mContext);
        tvLoadContet.setTag(1);
        tvLoadContet.setTextColor(ContextCompat.getColor(mContext, R.color.grey_A2A2A2));
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        layoutParams.topMargin = 15;
        layoutParams.bottomMargin = 15;
        this.addView(tvLoadContet,layoutParams);
        this.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
    }

    /**
     * 改变底部加载状态
     * @param status
     */
    public void setLoadStatus(int status) {
        this.mStatus = status;
        switch (status) {
            case STATUS_NORMAL:
                tvLoadContet.setText("");
                break;
            case STATUS_LOADING:
                tvLoadContet.setText("加载中...");
                break;
            case STATUS_LOAD_COMPLETEED:
                tvLoadContet.setText("加载数据完毕");
                break;
            case STATUS_LOAD_OVER:
                tvLoadContet.setText("已经到底了");
                break;
        }
    }
}
